package com.config;

import com.hdb.*;
import com.hdb.dao.Hib;
import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.struts2.util.Counter;
import org.hibernate.Hibernate;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.env.Environment;

import javax.inject.Inject;

/**
 * Created by aszer on 2016/11/9.
 */
@Configuration
public class AppConfig {
    @Inject
    SessionFactory sessionFactory;

    //ApplicationContext ctx = new ClassPathXmlApplicationContext();// 读取bean.xml中的内容
    //SessionFactory sf=env.getProperty("sessionFactory");//=(SessionFactory) ctx.getBean("sessionFactory");
    @Bean(name = "adminDAO")
    public Hib<TAdmin> tAdminHib() {
        Hib result = new Hib<>(Hib.TAdmin);
        result.setSessionFactory(sessionFactory);
        return result;
    }

    @Bean(name = "goodDAO")
    public Hib<TGood> tGoodHib() {
        Hib result = new Hib<>(Hib.TGood);
        result.setSessionFactory(sessionFactory);
        return result;
    }

    @Bean(name = "orderDAO")
    public Hib<TMyOrder> tMyOrderHib() {
        Hib result = new Hib<>(Hib.TMyOrder);
        result.setSessionFactory(sessionFactory);
        return result;
    }

    @Bean(name = "orderGoodDAO")
    public Hib<TOrderGood> tOrderGoodHib() {
        Hib result = new Hib<>(Hib.TOrderGood);
        result.setSessionFactory(sessionFactory);
        return result;
    }

    @Bean(name = "classDAO")
    public Hib<TClassification> tClassificationHib() {
        Hib result = new Hib<>(Hib.TClassification);
        result.setSessionFactory(sessionFactory);
        return result;
    }

    @Bean(name = "userDAO")
    public Hib<TUser> tUserHib() {
        Hib result = new Hib<>(Hib.TUser);
        result.setSessionFactory(sessionFactory);
        return result;
    }

    @Bean(name = "noticeDAO")
    public Hib<TNotice> tNoticeHib() {
        Hib result = new Hib<>(Hib.TNotice);
        result.setSessionFactory(sessionFactory);
        return result;
    }

    @Bean(name = "commentDAO")
    public Hib<TComment> tCommentHib() {
        Hib result = new Hib<>(Hib.TComment);
        result.setSessionFactory(sessionFactory);
        return result;
    }
    @Bean(name = "tableInfoDAO")
    public Hib<TComment> tTableInfoHib() {
        Hib result = new Hib<>(Hib.TTableInfo);
        result.setSessionFactory(sessionFactory);
        return result;
    }


}
